{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9b47ee8",
   "metadata": {},
   "source": [
    "# python的输入函数input()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df114a46",
   "metadata": {},
   "source": [
    "## input 函数介绍"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86b89b1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "present=input(\"想要什么礼物？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d87b0a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=input(\"他叫什么呢？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cad6f3b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "b=input(\"哈哈\")\n",
    "print(type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c797d080",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=input(\"请输入一个加数:\")\n",
    "a=int(a)#将转换后的结果存到a当中\n",
    "b=input(\"请输入一个加数:\")\n",
    "b=int(b)\n",
    "print(type(a),type(b))\n",
    "a+b\n",
    "\n",
    "#通过结果我们会发现，两个数字并没有相加\n",
    "#这个+其实起到了 连接 的作用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93d68871",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=int(input(\"请输入一个加数:\"))\n",
    "\n",
    "b=int(input(\"请输入一个加数:\"))\n",
    "\n",
    "print(type(a),type(b))\n",
    "a+b\n",
    "\n",
    "#这个方法比上面那个方法简洁，也可以这样转换\n",
    "#它的返回值为 str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69d7c32f",
   "metadata": {},
   "source": [
    "## python常用的运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8ec20edc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5\n",
      "5\n",
      "1\n",
      "4\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "#加减乘除\n",
    "\n",
    "print(1/2)#这个后面会显示小数点\n",
    "print(11//2)# 这个是整除运算\n",
    "print(11%2)#取余运算\n",
    "print(2**2)#表示的是2的2次方\n",
    "print(2**3)#表示2的3次方"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2891393e",
   "metadata": {},
   "source": [
    "### 一正一负的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6f41432a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "-3\n",
      "-3\n",
      "-3\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "print(-9//-4)\n",
    "\n",
    "print(9//-4)\n",
    "print(-9//4)\n",
    "#向下取整\n",
    "#所以两个都是-3\n",
    "\n",
    "print(9%-4) #-3 余数=被除数-除数*商。9-(-4)*(-3)= 9-12=-3\n",
    "print(-9%4)# 3.   -9-4*(-3) == -9+12= 3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "540376c4",
   "metadata": {},
   "source": [
    "### 赋值运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "00a999d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "# 运算顺序从右往左\n",
    "a=3+4\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "741eafb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20 140179679669136\n",
      "20 140179679669136\n",
      "20 140179679669136\n"
     ]
    }
   ],
   "source": [
    "#链式赋值，实际只有一个整数对象，但是却有abc三个引用指向了这个对象\n",
    "a=b=c=20\n",
    "print(a,id(a))\n",
    "print(b,id(b))\n",
    "print(c,id(c))\n",
    "#int 类型\n",
    "#value 是20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "53bd0186",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50\n",
      "40\n",
      "400\n",
      "30.76923076923077\n",
      "15.0\n",
      "3.0\n"
     ]
    }
   ],
   "source": [
    "# 支持参数赋值\n",
    "\n",
    "a=20\n",
    "a+=30 \n",
    "print(a)\n",
    "a-=10\n",
    "print(a)\n",
    "a*=10\n",
    "print(a)\n",
    "a/=13\n",
    "print(a)#这个时候变成了float类型\n",
    "a//=2\n",
    "print(a)\n",
    "a%=4\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b13797ca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20 30 40\n"
     ]
    }
   ],
   "source": [
    "a,b,c=20,30,40\n",
    "print(a,b,c)\n",
    "#解包赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "12406cc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "交换之前: 10 20\n",
      "交换之后: 20 10\n"
     ]
    }
   ],
   "source": [
    "#交换两个变量的值\n",
    "a,b=10,20\n",
    "print(\"交换之前:\",a,b)\n",
    "a,b=b,a\n",
    "print(\"交换之后:\",a,b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef49d554",
   "metadata": {},
   "source": [
    "### 比较运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "1c899ecb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "# 对变量或表达式的结果进行大小，真假等比较\n",
    "a,b=10,20\n",
    "print(a>b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "8003bec1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(a<b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "7033efde",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(a!=b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "15ff1319",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(a<=b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ace76119",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(a>=b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "619a8e78",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "140179679668816 140179679668816\n"
     ]
    }
   ],
   "source": [
    "#一个= 为赋值运算符，==为比较运算符\n",
    "#一个变量由三部分组成，标识，类型，值\n",
    "#== 比较的是值还是标识呢，比较的是值\n",
    "#比较对象的标识使用 is\n",
    "a=10\n",
    "b=10\n",
    "print(a==b)\n",
    "print(id(a),id(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "86689ae3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(a is b)\n",
    "#说明 a和b的id标识，相等"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "3bf5cd7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "#以下代码没学过，后面会给大家讲解\n",
    "lst1=[11,22,33,44]\n",
    "lst2=[11,22,33,44]\n",
    "print(lst1==lst2)\n",
    "print(lst1 is lst2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "bc869c09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "140179142740608\n",
      "140179142700736\n"
     ]
    }
   ],
   "source": [
    "print(id(lst1))\n",
    "print(id(lst2))\n",
    "#id不相等，所以是False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d20165c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(a is not b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b167e78a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(lst1 is not lst2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3a9e590",
   "metadata": {},
   "source": [
    "### 布尔运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "8cf89778",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "a,b=1,2\n",
    "print(a==1 and b==2)\n",
    "# True and Ttue--- True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "0edc5ff2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(a==1 and b!=2)\n",
    "# True and False--False\n",
    "# False and False --- False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "810126c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "# or 或者的关系\n",
    "print(a==1 or b==3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "082bd087",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(a==2 or b!=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e3d198d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "#对 运算数取反\n",
    "f=True\n",
    "f1=False\n",
    "print(not f)\n",
    "print(not f1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "2de754a5",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "# in and not in\n",
    "s=\"hello world\"\n",
    "print(\"w\"in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "d79b26d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(\"p\"in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "4f22abed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "print(\"h\"not in s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "8d1fc127",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(\"h\"in s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c101fe76",
   "metadata": {},
   "source": [
    "### 位运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "0e3b1c95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "# 位与 & 对应数位都是1，结果数位才是1，否则为0\n",
    "# 位或 ｜对应数位都是0，结果数位才是0，否则为1\n",
    "# 向左移动一位相当于乘以2，高位溢出，低位补0\n",
    "# 右移位 高位补0，低位截断，向右移动一位，相当于除2\n",
    "\n",
    "print(4&8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "403f41d0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n"
     ]
    }
   ],
   "source": [
    "print(4|8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "c486d6da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "print(4<<1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a0219730",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "print(4>>1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "1a353e4f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "32\n"
     ]
    }
   ],
   "source": [
    "print(4<<3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "23507cf2",
   "metadata": {},
   "source": [
    "### 运算符的优先级"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44496b9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.算术运算符 ** /,//,+,-\n",
    "# 2.位运算 << >> & |\n",
    "# 3.比较运算符 > < => <= and or \n",
    "# 4.布尔运算 True and False\n",
    "# 5.赋值运算符 =\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
